package com.zhou.controller;

import com.zhou.constant.MessageConstant;
import com.zhou.entity.PageResult;
import com.zhou.entity.QueryPageBean;
import com.zhou.entity.Result;
import com.zhou.pojo.Cmedicine;
import com.zhou.pojo.CmedicineMember;
import com.zhou.pojo.Psychological;
import com.zhou.pojo.PsychologicalMember;
import com.zhou.service.HealthService;
import jdk.nashorn.internal.ir.annotations.Reference;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/health")
public class HealthController {
    @Reference
    HealthService healthService;
    //查询所有
    @RequestMapping("findAllPsychological")
    public Result findAllPsychological(){
        try {
            List<Psychological>list =healthService.findAllPsychological();
            return new Result(true, MessageConstant.QUERY_PSYCHOLOGICAL_SUCCESS,list);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,MessageConstant.QUERY_PSYCHOLOGICAL_FAIL);
        }
    }
    @RequestMapping("/findAllCmedicine")
    public Result findAllCmedicine(){
        try {
            List<Cmedicine>list =healthService.findAllCmedicine();
            return new Result(true, MessageConstant.QUERY_CHECKITEM_SUCCESS,list);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_CHECKITEM_FAIL);
        }
    }
    //添加会员
    @RequestMapping("/addPsychologicalMember")
    public Result addPsychologicalMember(@RequestBody PsychologicalMember psychologicalMember, @Param("answerList") Integer[] answerList){
        try {
            healthService.addPsychologicalMember(psychologicalMember,answerList);
            return new Result(true,MessageConstant.ADD_PSYCHOLOGICALMEMBER_SUCCESS);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,MessageConstant.ADD_PSYCHOLOGICALMEMBER_FAIL);
        }
    }
    @RequestMapping("/addCmedicineMember")
    public Result addCmedicineMember(@RequestBody CmedicineMember CmedicineMember, @Param("answerList") Integer[] answerList){
        try {
            healthService.addCmedicineMember(CmedicineMember,answerList);
            return new Result(true,MessageConstant.ADD_CHECKGROUP_SUCCESS);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,MessageConstant.ADD_CHECKGROUP_FAIL);
        }
    }
    //分页查
    @RequestMapping("/findPsychologicalMemberByPage")
    public PageResult findPsychologicalMemberByPage(@RequestBody QueryPageBean queryPageBean){
        return healthService.findPsychologicalMemberByPage(queryPageBean);
    }
    @RequestMapping("/findCmedicineMemberByPage")
    public PageResult findCmedicineMemberByPage(@RequestBody QueryPageBean queryPageBean){
        return healthService.findCmedicineMemberByPage(queryPageBean);
    }
    //id查
    @RequestMapping("/findPsychologicalMemberById")
    public Result findPsychologicalMemberById(Integer id){
        try {
            List<PsychologicalMember>list=healthService.findPsychologicalMemberById(id);
            return new Result(true,MessageConstant.QUERY_PSYCHOLOGICAL_SUCCESS,list);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,MessageConstant.QUERY_PSYCHOLOGICAL_FAIL);
        }
    }
    @RequestMapping("/findCmedicineMemberById")
    public Result findCmedicineMemberById(Integer id){
        try {
            List<CmedicineMember>list=healthService.findCmedicineMemberById(id);
            return new Result(true,MessageConstant.QUERY_CMEDICINEMEMBER_SUCCESS,list);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,MessageConstant.QUERY_CMEDICINEMEMBER_FAIL);
        }
    }
    //修改
    @RequestMapping("/editPsychologicalMember")
    public Result editPsychologicalMember(@RequestBody PsychologicalMember psychologicalMember){
        try {
            healthService.editPsychologicalMember(psychologicalMember);
            return new Result(true,MessageConstant.EDIT_PSYCHOLOGICALMEMBER_SUCCESS);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,MessageConstant.EDIT_PSYCHOLOGICALMEMBER_FAIL);
        }
    }
    @RequestMapping("/editCmedicineMember")
    public Result editCmedicineMember(@RequestBody CmedicineMember cmedicineMember){
        try {
            healthService.editCmedicineMember(cmedicineMember);
            return new Result(true,MessageConstant.EDIT_CMEDICINEMEMBER_SUCCESS);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,MessageConstant.EDIT_CMEDICINEMEMBER_FAIL);
        }
    }
    //删除
    @RequestMapping("deletePsychologicalMemberById")
    public Result deletePsychologicalMemberById(Integer id){
        try {
            healthService.deletePsychologicalMemberById(id);
            return new Result(true,MessageConstant.DELETE_PSYCHOLOGICALMEMBER_SUCCESS);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,MessageConstant.DELETE_PSYCHOLOGICALMEMBER_FAIL);
        }
    }
    @RequestMapping("deleteCmedicineMemberById")
    public Result deleteCmedicineMemberById(Integer id){
        try {
            healthService.deleteCmedicineMemberById(id);
            return new Result(true,MessageConstant.DELETE_CMEDICINEMEMBER_SUCCESS);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,MessageConstant.DELETE_CMEDICINEMEMBER_FAIL);
        }
    }
}
